package com.server.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.server.model.OsaUserInfo;
import com.server.service.IOsaUserInfoService;
import com.server.utils.BaseResult;
import com.server.utils.UserSessionMapUtils;

@RestController
@RequestMapping(value = "/register")
public class WXAppRegisterController {
	
	private static Logger logger = Logger.getLogger(WXAppRegisterController.class);

	@Autowired
	private IOsaUserInfoService iOsaUserInfoService;

	@RequestMapping(value = "/subbmit")
	public JSONObject subbmit(@RequestParam String sessionCode, @RequestParam String realName, @RequestParam String phoneNum, @RequestParam String qq,
			String weChat, String phoneNum2, String qqName) {
		logger.info("完善用户信息");
		BaseResult result = new BaseResult();
		OsaUserInfo user = UserSessionMapUtils.getUserInfo(sessionCode);
		if (user == null) {
			result.setCode("102");
			result.setMsg("session失效，请重新登录");
		} else {
			user.setRealName(realName);
			user.setPhoneNum(phoneNum);
			user.setQq(qq);
			if (weChat != null) {
				user.setWechat(weChat);
			}
			if (phoneNum2 != null) {
				user.setPhoneNum2(phoneNum2);
			}
			if (qqName != null) {
				user.setQqName(qqName);
			}
			iOsaUserInfoService.updateOsaUserInfo(user);
			UserSessionMapUtils.putUser(sessionCode, user);
			result.setCode("100");
			result.setMsg("提交成功");
		}
		return JSONObject.parseObject(JSON.toJSON(result).toString());
	}
}
